package com.erb.controller.zwj.admin;

import com.erb.entity.Pager;
import com.erb.entity.RespBean;
import com.erb.service.zwj.IAdminUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RequestMapping("/admin/user")
public class AdminUserController {
	@Resource
	private IAdminUserService adminUserService;

	@GetMapping("/list")
	public String list(Model model, Pager pager) {
		pager.page(adminUserService.findCount());

		model.addAttribute("pager", pager);
		return "admin/user/list";
	}

	@ResponseBody
	@GetMapping("/listJson")
	public RespBean listJson(Pager pager) {
		return RespBean.ok("查询成功！", adminUserService.findAllForSimpleList(pager));
	}

	@ResponseBody
	@GetMapping("/{id}")
	public RespBean get(@PathVariable("id") Integer id) {

		return RespBean.ok("查询成功！", adminUserService.findUser(id));
	}

	@ResponseBody
	@PostMapping("/remove/{id}")
	public RespBean remove(@PathVariable("id") Integer id) {

		return RespBean.ok("删除成功！", adminUserService.removeUser(id));
	}
}
